import time
from selenium.webdriver.common.by import By
from base.page_base import BasePage


class LoanPage(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.financia = (By.XPATH, '//*[@id="mlayout"]/div[1]/div[2]/div/ul/li[3]/a')
        self.loan = (By.XPATH, '//*[@id="mlayout"]/div[1]/div[2]/div/ul/li[3]/ul/li[1]/a')
        self.crdeit = (By.XPATH, '//*[@id="ng-app"]/body/div[2]/div/ul/li[1]/dl/dd[5]/a')
        self.title = (By.XPATH, '//*[@id="borrowPublish"]/div[3]/input')
        self.purpose = (By.XPATH, '//*[@id="borrowPublish"]/div[4]/select')
        self.amount = (By.XPATH, '//*[@id="borrowPublish"]/div[5]/input')
        self.annual_interest_rate = (By.XPATH, '//*[@id="borrowPublish"]/div[6]/input')
        self.deadline = (By.XPATH, '//*[@id="borrowPublish"]/div[10]/select')
        self.min = (By.XPATH, '//*[@id="tender_amount_min"]')
        self.max = (By.XPATH, '//*[@id="tender_amount_max"]')
        self.describe = (By.XPATH, '//*[@id="borrow_contents"]')
        self.card = (By.XPATH, '//*[@id="borrowPublish"]/div[16]/input')
        self.submit = (By.XPATH, '//*[@id="borrowForm"]')

    def personal_loan(self):
        time.sleep(1)
        self.action_move(self.financia)
        self.base_click(self.loan)
        time.sleep(1)
        # 信用标
        handles = self.driver.window_handles
        self.driver.switch_to.window(handles[1])
        self.base_click(self.crdeit)

    def apply_submit(self):
        # 申请提交
        self.base_input(self.title, "测试")
        self.select_click(self.purpose, "1")
        self.base_input(self.amount, "1000")
        self.base_input(self.annual_interest_rate, "5")
        self.select_click(self.deadline, "9")
        self.select_click(self.min, "0")
        self.select_click(self.max, "4")
        self.base_input(self.describe, "测试")
        self.base_input(self.card, "8888")
        self.base_click(self.submit)
